package com.yztc.love_travel.adater.fourtrip;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yztc.love_travel.R;
import com.yztc.love_travel.bean.fourtrip.FourTripBean;
import com.yztc.love_travel.constant.OtherConstant;
import com.yztc.love_travel.constant.URLConstant;
import com.yztc.love_travel.ui.fourtrip.FourTripDetailsActivity;

import java.util.List;

/**
 * Created by 周旭 on 2016/11/29.
 * "四大推荐旅游路线"的适配器
 */

public class FourTripAdapter extends RecyclerView.Adapter<FourTripAdapter.ReligionCultureViewHolder>{

    private List<FourTripBean.ListBean.DestinationListBean> mList;
    private LayoutInflater inflater;
    private Context context;

    public FourTripAdapter(Context context, List<FourTripBean.ListBean.DestinationListBean> mList) {
        this.mList = mList;
        this.context = context;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public ReligionCultureViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = inflater.inflate(R.layout.religion_culture_item,parent,false);
        return new ReligionCultureViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(ReligionCultureViewHolder holder, int position) {
        //关联数据
        final FourTripBean.ListBean.DestinationListBean destinationListBean = mList.get(position);
        holder.titleTv.setText(destinationListBean.getTitle()); //设置标题
        String picUrl = URLConstant.ReligionCulture.URL_REGION_CULTURE_ITEM_DETAILS + destinationListBean.getPicUrl();
        Glide.with(context).load(picUrl)
                .placeholder(R.mipmap.logo)
                .error(R.mipmap.logo)
                .into(holder.iv); //设置图片
        holder.introTv.setText(destinationListBean.getIntro()); //设置简介
        //点击事件
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int id = destinationListBean.getId();
                Intent intent = new Intent(context, FourTripDetailsActivity.class);
                intent.putExtra(OtherConstant.KEY_DESTINATION_ID,id);
                context.startActivity(intent);
            }
        });
    }

     class  ReligionCultureViewHolder extends RecyclerView.ViewHolder{
        private TextView titleTv; //标题
        private ImageView iv; //大图
        private TextView introTv; //简介

        public ReligionCultureViewHolder(View itemView) {
            super(itemView);
            titleTv = (TextView) itemView.findViewById(R.id.religion_culture_title_tv);
            iv = (ImageView) itemView.findViewById(R.id.religion_culture_pic_iv);
            introTv = (TextView) itemView.findViewById(R.id.religion_culture_content_intro_tv);

        }
    }
}
